package controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Map;

@Controller
public class LoginController {
    // @RequestMapping("/showLogin")
    // public ModelAndView show(){
    //     System.out.println("LoginController.show()");
    //     return new ModelAndView("login");
    // }

    @RequestMapping("/login")
    public String login(String username, String password, Map map, HttpSession session){
        System.out.println("LoginController.login()");

        System.out.println("username = " + username);
        System.out.println("password = " + password);


        if("abc".equals(username)&&"123".equals(password)){
            session.setAttribute("user",username);
            return "redirect:/showSuccess";
        }

        map.put("message","用户名或密码错误");


        return "login";

        // return "success";
        // return "forward:/WEB-INF/jsp/success.jsp";
        // return "redirect:/showSuccess";
    }

}
